﻿using System;

public class KeyboardInput : IUserInterface
{
    public event EventHandler OnLeftPressed;
    public event EventHandler OnUpPressed;
    public event EventHandler OnRightPressed;
    public event EventHandler OnDownPressed;
    public event EventHandler OnOpenPressed;
    public event EventHandler OnMarkPressed;

    public void ProcessInput()
    {
        while (Console.KeyAvailable)
        {
            var keyInfo = Console.ReadKey(true);

            if (keyInfo.Key.Equals(ConsoleKey.LeftArrow))
            {
                if (this.OnLeftPressed != null)
                {
                    this.OnLeftPressed(this, new EventArgs());
                }
            }

            if (keyInfo.Key.Equals(ConsoleKey.UpArrow))
            {
                if (this.OnUpPressed != null)
                {
                    this.OnUpPressed(this, new EventArgs());
                }
            }

            if (keyInfo.Key.Equals(ConsoleKey.RightArrow))
            {
                if (this.OnRightPressed != null)
                {
                    this.OnRightPressed(this, new EventArgs());
                }
            }

            if (keyInfo.Key.Equals(ConsoleKey.DownArrow))
            {
                if (this.OnDownPressed != null)
                {
                    this.OnDownPressed(this, new EventArgs());
                }
            }

            if (keyInfo.Key.Equals(ConsoleKey.Enter))
            {
                if (this.OnOpenPressed != null)
                {
                    this.OnOpenPressed(this, new EventArgs());
                }
            }

            if (keyInfo.Key.Equals(ConsoleKey.Spacebar))
            {
                if (this.OnMarkPressed != null)
                {
                    this.OnMarkPressed(this, new EventArgs());
                }
            }
        }
    }
}
